<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%@ page import="fr.mywiki.view.web.struts.form.admin.structure.ManageStructureForm" %>

<html:hidden property="actionType" value="error"/>

<script>
<!--
	function modifyCurrent() {
		document.forms["manageStructureForm"].method.value='modifyCurrent';
		document.forms["manageStructureForm"].submit();
	}
	
	function createChild() {
		document.forms["manageStructureForm"].method.value='initCreation';
		document.forms["manageStructureForm"].submit();
	}
	
	function removeCurrent() {
		if(confirm('<bean:message key="admin.structure.remove.confirm"/>')) {
			document.forms["manageStructureForm"].method.value='removeCurrent';
			document.forms["manageStructureForm"].submit();
		}
	}

	function validateEdition() {
		document.forms["manageStructureForm"].method.value='validateEdition';
		document.forms["manageStructureForm"].submit();
	}

	function cancelEdition() {
		document.forms["manageStructureForm"].method.value='cancelEdition';
		document.forms["manageStructureForm"].submit();
	}
	
	function manageAccounts() {
		document.forms["manageStructureForm"].method.value='manageAccounts';
		document.forms["manageStructureForm"].submit();
	}
	
	function selectChanged() {
		var actionValue = document.forms["manageStructureForm"].structureActionSelect.value;
		if (actionValue=='createChild')
			createChild();
		if (actionValue=='modifyCurrent')
			modifyCurrent();
		if (actionValue=='removeCurrent')
			removeCurrent();
		if (actionValue=='manageAccounts')
			manageAccounts();
	}

	function updateSelect(isRoot) {
		var theSelect = document.forms['manageStructureForm'].structureActionSelect;
		if (theSelect!=null) {
			// i.e. we are not in edition mode
			// Root menu
			theSelect.options[0] =
				new Option("<bean:message key="action.list.nothing"/>","");
			theSelect.options[1] =
				new Option("<bean:message key="admin.structure.create"/>","createChild");
			if(isRoot=="false") {
				// Complete with standard menu
				theSelect.options[2] =
					new Option("<bean:message key="admin.structure.modify"/>", "modifyCurrent");
				theSelect.options[3] =
					new Option("<bean:message key="admin.structure.remove"/>", "removeCurrent");
				theSelect.options[4] =
					new Option("<bean:message key="admin.user.see.struct.acc"/>","manageAccounts");
			} else {
				theSelect.options[4] = null;
				theSelect.options[3] = null;
				theSelect.options[2] = null;
			}
		} else {
			// i.e we are in edition mode : cancel edition
			cancelEdition();
		}
	}
-->
</script>

<div id="detailsContainer">

	<logic:equal value="<%=ManageStructureForm.CONSULTING_MODE%>" property="currentMode" name="manageStructureForm">
		<h1><bean:message key="admin.structure.details"/></h1>
		<br/>
		<bean:message key="structure.field.name"/>&nbsp;:&nbsp;
		<span id="structName">
			<bean:write name="manageStructureForm" property="structName"/>
		</span>
		<br/>
		
		<select id="structureActionSelect" onchange="javascript:selectChanged();" >
			<option value=""><bean:message key="action.list.nothing"/></option>
			<option value="createChild">
				<bean:message key="admin.structure.create"/>
			</option>
			<logic:notEmpty property="idStructure" name="manageStructureForm">
				<option value="modifyCurrent" id="modifyCurrentOption" style="hidden">
					<bean:message key="admin.structure.modify"/>
				</option>
				<option value="removeCurrent" id="removeCurrentOption" style="hidden">
					<bean:message key="admin.structure.remove"/>
				</option>
				<option value="manageAccounts" id="manageAccountsOption" style="hidden">
					<bean:message key="admin.user.see.struct.acc"/>
				</option>
			</logic:notEmpty>
		</select>
	</logic:equal>

	<logic:notEqual value="<%=ManageStructureForm.CONSULTING_MODE%>" property="currentMode" name="manageStructureForm">
		<h1><bean:write name="manageStructureForm" property="introSentence"/></h1>
		<br/>
		<bean:message key="structure.field.name"/>&nbsp;:&nbsp;
		<html:text property="structName" name="manageStructureForm"/>
		<br/>
		<a href="javascript:validateEdition();">
			<bean:message key="action.validate"/>
		</a>
		&nbsp;
		<a href="#" onclick="javascript:cancelEdition();">
			<bean:message key="action.cancel"/>
		</a>
	</logic:notEqual>

</div>